from browser . logic import browser_logic

class mediator_fake :
    def __init__ ( self ) :
        self . _browser_logic = None
        self . _knowledge_base_receiving_callback = None
        self . _all_knowledge_bases = [ ]
        self . _entry_text = None
        self . _entry_text_on_browser_action = [ ]
        self . _title_text_in_browser = [ ]
    def add_title_label_to_browser ( self , title_text ) :
        pass
    def add_table_to_browser ( self ) :
        pass
    def add_return_button_to_browser ( self ) :
        pass
    def add_action_button_to_browser ( self , action_text ) :
        pass
    def add_title_row_to_browser ( self , number , name , creation_time , modification_time , size ) :
        pass
    def add_existing_row_to_browser ( self , number , name , creation_time , modification_time , size ) :
        pass
    def add_empty_row_to_browser ( self ) :
        pass
    def add_action_row_to_browser ( self ) :
        pass
    def set_entry_text_in_browser ( self , text ) :
        self . _entry_text = text
    def entry_text_in_browser_request ( self ) :
        self . _browser_logic . entry_text_in_browser_reply ( self . _entry_text )
    def focus_entry_in_browser ( self ) :
        pass
    def select_table_row ( self , row ) :
        pass
    def localization_browser_number ( self ) :
        pass
    def localization_browser_existing_name ( self ) :
        pass
    def localization_browser_creation_time ( self ) :
        pass
    def localization_browser_modification_time ( self ) :
        pass
    def localization_browser_size ( self ) :
        pass
    def fetch_all_knowledge_bases ( self ) :
        for kb in self . _all_knowledge_bases :
            self . _knowledge_base_receiving_callback ( * kb )
    def on_browser_action ( self ) :
        self . _entry_text_on_browser_action += [ self . _entry_text ]
    def bold_table_row ( self , row ) :
        pass
    def set_title_text_in_browser ( self , text ) :
        self . _title_text_in_browser += [ text ]
    
class browser_logic_on_browser_action_gui_button_tests :
    'browser_logic_on_browser_action_gui_button'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _browser_logic = browser_logic ( self . _mediator )
        self . _mediator . _browser_logic = self . _browser_logic
    def test_on_browser_action_gui_button_filter_item_text ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = [ [ 'my name' , None , 'my time' , None ] ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = '   !@#$%^&*()_+valid    name  part123  ; \',./\\][}{   '
        self . _browser_logic . on_browser_action_gui_button ( )
        self . _test . assume_equal ( self . _mediator . _entry_text_on_browser_action , [ 'valid name part123' ] )
    def test_on_browser_action_gui_button_check_uniqueness ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'my name1' , None , 'my time1' , None ]
            , [ 'my name2' , None , 'my time2' , None ]
            ]
        self . _browser_logic . configure_only_unique_names_mode_for_browser ( 'my already exists' )
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = '   !@#$my   name1   !@#$ '
        self . _browser_logic . on_browser_action_gui_button ( )
        self . _test . assume_empty ( self . _mediator . _entry_text_on_browser_action )
        self . _test . assume_equal ( self . _mediator . _title_text_in_browser , [ 'my already exists' ] )
    def test_on_browser_action_gui_button_dont_check_uniqueness ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'my name1' , None , 'my time1' , None ]
            , [ 'my name2' , None , 'my time2' , None ]
            ]
        self . _browser_logic . configure_only_unique_names_mode_for_browser ( None )
        self . _browser_logic . configure_unique_or_existing_names_mode_for_browser ( )
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = 'my name1'
        self . _browser_logic . on_browser_action_gui_button ( )
        self . _test . assume_equal ( self . _mediator . _entry_text_on_browser_action , [ 'my name1' ] )
        self . _test . assume_empty ( self . _mediator . _title_text_in_browser )
    def test_on_browser_action_gui_button_dont_check_uniqueness_by_default ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'my name1' , None , 'my time1' , None ]
            , [ 'my name2' , None , 'my time2' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_text = 'my name1'
        self . _browser_logic . on_browser_action_gui_button ( )
        self . _test . assume_equal ( self . _mediator . _entry_text_on_browser_action , [ 'my name1' ] )
        self . _test . assume_empty ( self . _mediator . _title_text_in_browser )
